package com.example.fly.common;

/**
 * 基于ThreadLocal封装工具类，用于保存和获取当前用户id
 */
public class BaseContext {
    private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
    private static ThreadLocal<Long> threadLocal2 = new ThreadLocal<>();

    public synchronized static void setCurrentId(Long id){
        threadLocal.set(id);
    }

    public synchronized static Long getCurrentId(){
        return threadLocal.get();
    }

    public synchronized static void removeCurrentId(){
        threadLocal.remove();
    }

    public synchronized static void setCurrentId2(Long id){
        threadLocal2.set(id);
    }

    public synchronized static Long getCurrentId2(){
        return threadLocal2.get();
    }

    public synchronized static void removeCurrentId2(){
        threadLocal2.remove();
    }
}
